/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.moedik.model;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Yudi Retanto
 */
public class LogModel{
    protected Connection con = null;
    
    public LogModel() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost/moedik", "root", "");
        } catch (SQLException ex) {
            Logger.getLogger(UserModel.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(UserModel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void log(String str){
        PreparedStatement stmt = null;
        try {
            String query = "INSERT INTO logs (info) VALUES ('"+str+"') ";
            stmt = con.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
            stmt.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(ConfigModel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void bookShuttle(int user_id,int service_id){
        PreparedStatement stmt = null;
        String str = "user "+user_id+" melakukan booking shuttle layanan "+service_id;
        try {
            String query = "INSERT INTO logs (info) VALUES ('"+str+"') ";
            stmt = con.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
            stmt.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(ConfigModel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void bookBus(int user_id,int service_id){
        PreparedStatement stmt = null;
        String str = "user "+user_id+" melakukan booking bus layanan "+service_id;
        try {
            String query = "INSERT INTO logs (info) VALUES ('"+str+"') ";
            stmt = con.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
            stmt.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(ConfigModel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void bookFlight(int user_id,int service_id){
        PreparedStatement stmt = null;
        String str = "user "+user_id+" melakukan booking flight layanan "+service_id;
        try {
            String query = "INSERT INTO logs (info) VALUES ('"+str+"') ";
            stmt = con.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
            stmt.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(ConfigModel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void confirmBook(String billno){
        PreparedStatement stmt = null;
        String str = billno+" telah dikonfirmasi";
        try {
            String query = "INSERT INTO logs (info) VALUES ('"+str+"') ";
            stmt = con.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
            stmt.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(ConfigModel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    void approveBook(int id) {
        PreparedStatement stmt = null;
        String str = id+" telah diapprove";
        try {
            String query = "INSERT INTO logs (info) VALUES ('"+str+"') ";
            stmt = con.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
            stmt.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(ConfigModel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
